/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author Alessandro
 */
@Entity
public class Event implements Serializable, Comparable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @NotNull(message="May not be empty")
    private String title;
    private String description;
    @NotNull (message = "A start date is required")
    @Temporal(TemporalType.TIMESTAMP)
    private Date startDate;
    @NotNull (message = "An end date is required")
    @Temporal(TemporalType.TIMESTAMP)
    private Date endDate;
    @NotNull (message = "A location is required")
    private Location location;
    @NotNull (message = "A value is required")
    private Visibility visibiltiy;
    @NotNull (message = "A country is required")
    private String country;
    @NotNull (message = "A city is required")
    private String city;
    private String address;
    private boolean deleted;
    
    
    @JoinColumn(name = "creator", referencedColumnName = "email")
    @ManyToOne(optional = false)
    private User creator;
    @JoinColumn(name = "forecast", referencedColumnName = "weatherId")
    @ManyToOne
    private Weather forecast;
        
        
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event1")
    private Collection<Participant> participantCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
    private Collection<Message> messageCollection;

    

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    public Visibility getVisibiltiy() {
        return visibiltiy;
    }

    public void setVisibiltiy(Visibility visibiltiy) {
        this.visibiltiy = visibiltiy;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }
    
    public Collection<Participant> getParticipantCollection() {
        return participantCollection;
    }

    public void setParticipantCollection(Collection<Participant> participantCollection) {
        this.participantCollection = participantCollection;
    }

    public Collection<Message> getMessageCollection() {
        return messageCollection;
    }

    public void setMessageCollection(Collection<Message> messageCollection) {
        this.messageCollection = messageCollection;
    }

    public Weather getForecast() {
        return forecast;
    }

    public void setForecast(Weather forecast) {
        this.forecast = forecast;
    }
    
    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Event)) {
            return false;
        }
        Event other = (Event) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Event[ id=" + id + " ]";
    }

    @Override
    public int compareTo(Object o) {
        Event first = (Event) o;
        if (first.getStartDate().before(this.startDate)) {
            return +1;
        } else {
            if (first.getStartDate().after(this.startDate)) {
                return -1;
            } else {
                return 0;
            }
        }
    }

}
